/**
  ******************************************************************************
  * File Name          : ctrl_shl.c
  * Description        : Code for data process applications
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "tskcfg.h"
#include "bsp.h"
#include "spiflash.h"
#include "collector.h"
#include "ctrl_common.h"

void Ctrl_dk(Sys_DataTimeType *tm)
{
  uint8_t i;
  uint32_t timestamp;
  
  timestamp = (tm->hour*3600)+(tm->minute*60)+tm->second;
  
  for(i=0; i<DKCTR_PT_CHANNEL_ALLNUM; i++)
  {
		if(Ctrl_ParaDK.dktm[i].dkkqtm1 < Ctrl_ParaDK.dktm[i].dkgbtm1)
		{
      /* 判断开区间  ________K--------------G________> */
			if((timestamp >= Ctrl_ParaDK.dktm[i].dkkqtm1) && (timestamp < Ctrl_ParaDK.dktm[i].dkgbtm1))
			{
				dk_act[i] = 1;
			}
      else
      {
        dk_act[i] = 0;
      }
		}
    else if(Ctrl_ParaDK.dktm[i].dkkqtm1 > Ctrl_ParaDK.dktm[i].dkgbtm1)
    {
      /* 判断关区间  --------G______________K--------> */
      if((timestamp >= Ctrl_ParaDK.dktm[i].dkgbtm1) && (timestamp < Ctrl_ParaDK.dktm[i].dkkqtm1))
			{
				dk_act[i] = 0;
			}
      else
      {
        dk_act[i] = 1;
      }
    }
    
		if(Ctrl_ParaDK.dktm[i].dkkqtm2 < Ctrl_ParaDK.dktm[i].dkgbtm2)
		{
      /* 判断开区间  ________K--------------G________> */
			if((timestamp >= Ctrl_ParaDK.dktm[i].dkkqtm2) && (timestamp < Ctrl_ParaDK.dktm[i].dkgbtm2))
			{
				dk_act[i] = 1;
			}
      else
      {
        dk_act[i] = 0;
      }
		}
    else if(Ctrl_ParaDK.dktm[i].dkkqtm2 > Ctrl_ParaDK.dktm[i].dkgbtm2)
    {
      /* 判断关区间  --------G______________K--------> */
      if((timestamp >= Ctrl_ParaDK.dktm[i].dkgbtm2) && (timestamp < Ctrl_ParaDK.dktm[i].dkkqtm2))
			{
				dk_act[i] = 0;
			}
      else
      {
        dk_act[i] = 1;
      }
    }
  }
}
